package cn.seqdata.util;

import java.util.Optional;

import org.joda.time.LocalDate;

public final class DateUtils {
	private DateUtils() {
	}

	/** 今天 */
	public static LocalDate today(LocalDate date) {
		return Optional.ofNullable(date)
			.orElse(LocalDate.now());
	}

	/** 昨天 */
	public static LocalDate yesterday(LocalDate date) {
		return today(date).minusDays(1);
	}

	/** 明天 */
	public static LocalDate tomorrow(LocalDate date) {
		return today(date).plusDays(1);
	}

	/** 上月当天 */
	public static LocalDate lastMonth(LocalDate date) {
		return today(date).minusMonths(1);
	}

	/** 去年当天 */
	public static LocalDate lastYear(LocalDate date) {
		return today(date).minusYears(1);
	}

	/** 本月第一天 */
	public static LocalDate theMonthFirst(LocalDate date) {
		return today(date).withDayOfMonth(1);
	}

	/** 今年第一天 */
	public static LocalDate theYearFirst(LocalDate date) {
		return today(date).withDayOfYear(1);
	}
}
